package com.team1.supervend.domain;

import java.util.ArrayList;
import java.util.HashMap;

import com.team1.supervend.domain.ProductDescription;

public class ProductInventory {
	private HashMap<ItemID, ProductDescription> productDescriptions = new HashMap<ItemID, ProductDescription>(); 

	public ArrayList<ProductInventoryItem> productInventoryItems = new ArrayList<ProductInventoryItem>();
	
	public ProductInventory() {
		//System.out.println("New ProductInventory");
	}

	public void ProvideProductInventory(ProductInventoryItem item) {
		productInventoryItems.add( item );
	}
	
	public void StockProductInventory(ProductInventoryItem item) {
		ProductDescription desc;
		//System.out.println("Stocking ProductInventory in SuperVend");
		ItemID         id          = item.getItemID();
		PaymentAmount  cost        = item.getCost();
		String         descr       = item.getDescription();
		int            quantity    = item.getQuantity(); 
		int            minQuantity = item.getMinQuantity(); 
		desc = new ProductDescription( id, cost, descr, quantity, minQuantity );
		productDescriptions.put( id, desc);
		ProvideProductInventory(item);

	}
	
	public void printProductDescriptions( ) {
		System.out.println("");
		System.out.println("---------------- ");
		System.out.println("Available Items List");
		System.out.println("---------------- ");

		// Get the array of ProductInventoryItems
		ProductInventoryItem a[] = new ProductInventoryItem[productInventoryItems.size()];
		a = productInventoryItems.toArray(a);

		for ( ProductInventoryItem i : a ) {
			ItemID    id    = i.getItemID();

			System.out.println("");
			productDescriptions.get( id ).PrintDescription();
			System.out.println("");
		}

		System.out.println("---------------- ");
		System.out.println("End of Available Items List");
		System.out.println("---------------- ");
		System.out.println("");
		return ;
	}

	public HashMap<ItemID, ProductDescription> getProductDescriptions( ) {
		return productDescriptions;
	}

	public ProductDescription getProductDescription( ItemID id ) {
		return productDescriptions.get( id );
	}

	public ItemID getItemID( int id ) {
		ItemID itemID = null;

		// Get the array of ProductInventoryItems
		ProductInventoryItem a[] = new ProductInventoryItem[productInventoryItems.size()];
		a = productInventoryItems.toArray(a);

		for ( ProductInventoryItem i : a ) {
			if ( i.getItemID().getItemID() == id ) {
				itemID    = i.getItemID();
			}
		}

		return itemID;
	}

}
